package com.victor.controller.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.victor.entity.collection.CollectionFolder;
import com.victor.service.CollectionfolderService;
import com.victor.utils.ClassFilter;
import com.victor.utils.Msg;

@RestController
@RequestMapping("/collectionfolder")
public class CollectionFolderController {
	@Autowired
	private CollectionfolderService service;
	
	/**
	 * 添加文件夹
	 * @param collectionFolder
	 * @return
	 */
	@RequestMapping("/addfolder")
	public Msg addFolder(CollectionFolder collectionFolder) {
		String[] strings = {"uid","name"};
		boolean empty = ClassFilter.somePropertyIsEmpty(collectionFolder, strings);
		if (empty == true) {
			return Msg.fail("入参错误");
		}
		boolean b = service.insertCollectionFolder(collectionFolder);
		return Msg.judge(b);
	}
	/**
	 * 删除文件夹
	 * @param ids
	 */
	@RequestMapping("/delfolder")
	public Msg deleteCollectionFolder(int[] ids) {
		if (ids == null || ids.length <= 0) {
			return Msg.fail("入参错误");
		}
		boolean b = service.delCollectionFolder(ids);
		return Msg.judge(b);
	}
	/**
	 * 我的-收藏列表
	 * @param uid
	 * @param page
	 * @param row
	 * @return
	 */
	@RequestMapping("/findfolder")
	public Msg findAllFolder(String uid,int page,int row) {
		if (uid == null || uid.isEmpty()) {
			return Msg.fail("入参错误");
		} 
		PageInfo<CollectionFolder> selAllFolder = service.selAllFolder(uid,page,row);
		return Msg.success().add("info", selAllFolder);
		
	}
	/**
	 * 修改文件夹
	 * @param folder
	 * @return
	 */
	@RequestMapping("/update")
	public Msg updateFolder(CollectionFolder folder) {
		String[] str = {"id","name"};
		boolean empty = ClassFilter.somePropertyIsEmpty(folder, str);
		if (empty ==true) {
			return Msg.fail("入参失败");
		}
		boolean b = service.updateFolder(folder);
		return Msg.judge(b);
	}
	
	

}
